package MainTest;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;


public class ServiceLocator {
	private String SERVIDOR_URL = "JMSTestingUnitEAR";
	private Tests tests;

	public ServiceLocator(){
		super(); 
		getConnection();
	}
	
	protected void getConnection() {
        try {
        	InitialContext initContext;
        	
        	//Context jndiContext = getInitialContext();
			Hashtable props = new Hashtable();
			props.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
			//Url completa de ubicacion del servidor de aplicaciones
			props.put(InitialContext.PROVIDER_URL,"jnp://127.0.0.1:1099");
			//Objeto del tipo InitialContext
			initContext = new InitialContext(props);

			setTests((Tests)initContext.lookup(SERVIDOR_URL
					+ "/TestsBean/remote"));
        } catch (Exception e) {
        	e.printStackTrace(); 
        }
    } 

    private static Context getInitialContext() throws javax.naming.NamingException {
        return new javax.naming.InitialContext();
    }

	public void setTests(Tests tests) {
		this.tests = tests;
	}

	public Tests getTests() {
		return tests;
	}

}
